package com.lijing.huffmanCode;

/**
 * @Description TODO
 * @title: Node
 * @Author LiJing
 * @Date: 2021/2/258:45 上午
 * @Version 1.0
 */
public class Node implements Comparable<Node>{
    private Byte data;
    private int weight;
    private Node left;
    private Node right;


    public Node() {
    }
    public Node(Byte data, int weight) {
        this.data = data;
        this.weight = weight;
    }

    /**
     * min-->max
     * @param o 待比较的Node
     * @return 返回当前-待比较
     */
    @Override
    public int compareTo(Node o) {
        return this.getWeight() - o.getWeight();
    }

    @Override
    public String toString() {
        return "Node{" +
                "data=" + data +
                ", weight=" + weight +
                '}';
    }

    /**
     * 前序遍历
     */
    public void preOrder(){
        System.out.println(this);
        if (this.getLeft() != null){
            this.left.preOrder();
        }
        if (this.getRight() != null){
            this.right.preOrder();
        }
    }

    public Byte getData() {
        return data;
    }

    public void setData(Byte data) {
        this.data = data;
    }

    public int getWeight() {
        return weight;
    }

    public void setWeight(int weight) {
        this.weight = weight;
    }

    public Node getLeft() {
        return left;
    }

    public void setLeft(Node left) {
        this.left = left;
    }

    public Node getRight() {
        return right;
    }

    public void setRight(Node right) {
        this.right = right;
    }
}
